package com.xuesinuo.ots.pojo;

import java.util.List;

import com.xuesinuo.ots.entity.Role;
import com.xuesinuo.ots.util.BeanUtil;
import com.xuesinuo.ots.util.JsonUtil;

import lombok.Data;
import lombok.EqualsAndHashCode;

/** 角色 - 扩展类 */
@Data
@EqualsAndHashCode(callSuper = true)
public class RolePojo extends Role {
    /** 菜单List */
    private List<String> menuList;
    /** 权限List */
    private List<String> authList;

    /** 菜单List getter */
    public List<String> getMenuList() {
        if (this.getMenuJson() == null) {
            return this.menuList;
        }
        return JsonUtil.toList(this.getMenuJson(), String.class);
    }

    /** 菜单List setter */
    public void setMenuList(List<String> list) {
        String menuJson;
        if (list == null) {
            menuJson = null;
        } else {
            menuJson = JsonUtil.toJson(list);
        }
        this.setMenuJson(menuJson);
        this.menuList = list;
    }

    /** 权限List getter */
    public List<String> getAuthList() {
        if (this.getAuthJson() == null) {
            return this.authList;
        }
        return JsonUtil.toList(this.getAuthJson(), String.class);
    }

    /** 权限List setter */
    public void setAuthList(List<String> list) {
        String authJson;
        if (list == null) {
            authJson = null;
        } else {
            authJson = JsonUtil.toJson(list);
        }
        this.setAuthJson(authJson);
        this.authList = list;
    }

    /** 通过Role初始化 */
    public static RolePojo init(Role role) {
        return BeanUtil.copy(role, new RolePojo());
    }

    /** RoleResult 转为 Role */
    public Role toRole() {
        return BeanUtil.copy(this, new Role());
    }
}